Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
How to capture time/date when message was send/button pressed [ Vanilla Javascript ]

Im working on a messaging app and i cant figure out how to capture time when SEND/Enter button was clicked and display it next to the message

Vanilla JS

Thank you!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So are you trying to display the time the button was clicked, and display it to the sender / recipient in their local time?

If so, you should just be able to use the Date constructor like so:

const date = new Date();

That will give you the UTC time. To convert to local time, you can use the .toLocaleTimeString() method. This would log your local time in US format:

const date = new Date();
console.log(date.toLocaleTimeString('en-US'));

So what you could do is have an event listener on the button, and when the button is clicked, create a new date, and convert to local time.

const button = document.querySelector('button');
const par = document.querySelector('p')

button.addEventListener('click', () => {
    const date = new Date();
  const local = date.toLocaleTimeString('en-US');
  par.innerHTML = local
})
<button>
Click me
</button>

<p>
</p>

JSFiddle: https://jsfiddle.net/f198wvdt/2/

Is this along the lines of what you're looking for?

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda